//
//  GoldenVPNRegistVC.m
//  QLadder
//
//  Created by xiongguobing on 2019/8/8.
//  Copyright © 2019 qding. All rights reserved.
//

#import "GoldenVPNRegistVC.h"
#import "IPToolManager.h"
#import "NSString+VerifyString.h"

@interface GoldenVPNRegistVC ()
@property (weak, nonatomic) IBOutlet UIView *subContentView;

@property (weak, nonatomic) IBOutlet UITextField *userNameTF;
@property (weak, nonatomic) IBOutlet UITextField *pwdTF;
@property (weak, nonatomic) IBOutlet UITextField *emailTF;
@property (weak, nonatomic) IBOutlet UITextField *addressTF;


@end

@implementation GoldenVPNRegistVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    for (UIView * subView in self.subContentView.subviews) {
        if ([subView isKindOfClass:[UITextField class]]) {
            UITextField * tf = (UITextField *)subView;
            [tf setValue:ThemeColor forKeyPath:@"_placeholderLabel.textColor"];
        }
    }
    
    self.title = @"注册";
    self.addressTF.text = self.currentCity ? : @"";
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)registButtonClicked:(UIButton *)sender
{
    if (!ValidStr(self.userNameTF.text)) {
        kShowWithString(@"请输入用户名");
        return;
    }
    if (!ValidStr(self.pwdTF.text) || ![self.pwdTF.text verifyWithPassword]) {
        kShowWithString(@"请输入符合规则的密码密码");
        return;
    }
    if (!ValidStr(self.emailTF.text) || ![self.emailTF.text verifyWithEmail]) {
        kShowWithString(@"请输入正确的邮箱");
        return;
    }
    if (!ValidStr(self.addressTF.text)) {
        kShowWithString(@"请输入注册所在地");
        return;
    }
    kDismissKeyboard;
    
    IPToolManager *ipManager = [IPToolManager sharedManager];
    NSDictionary * IPDic = [ipManager currentIPAdressDetailInfo];
    NSString * IPStr = [ipManager currentIpAddress];
    NSString * MACStr = IPDic[@"mac"];
    NSDictionary * dic = @{@"userName" : self.userNameTF.text, @"userMail" : self.emailTF.text, @"passWord" : self.pwdTF.text, @"cityAreacode"  : self.currentCity ?: self.addressTF.text, @"imei" : @"-1", @"imsi" : @"-1", @"mac" : MACStr ? : @"-1", @"srcIp" : IPStr ? : @"-1", @"srcPort" : @"-1",};
    [kNetworkUtil postWithModuleURLStr:regist parameters:dic success:^(id response) {
        if ([[response objectForKey:@"code"] integerValue] == 200) {
            [kUserDefaults setObject:self.emailTF.text forKey:kUserAccount];
            [kUserDefaults setObject:self.pwdTF.text forKey:kUserPassword];
            [kUserDefaults synchronize];
            
            if (self.block) {
                self.block(self.userNameTF.text, self.pwdTF.text);
            }
            kShowWithString(@"注册成功!");
            [self.navigationController popViewControllerAnimated:YES];
        }
    } failure:nil withHud:YES];

}

- (void)uploadRegistLog
{
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
